package com.haiheng.pullup

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import com.xuanyuan.pullup.ApkUtils
import com.xuanyuan.pullup.PullUpUtils

class TestActivity : AppCompatActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)
        initView()
    }

    private fun initView() {
        findViewById<Button>(R.id.btnPullUpByPackage).setOnClickListener(this)
        findViewById<Button>(R.id.btnPullUpOnlyPackage).setOnClickListener(this)
        findViewById<Button>(R.id.btnPullUpByUri).setOnClickListener(this)
        findViewById<Button>(R.id.btnPullUpSpecifyConditions).setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        if (v == null) {
            return
        }
        when (v.id) {
            R.id.btnPullUpByPackage -> pullUpByPackage()
            R.id.btnPullUpOnlyPackage -> pullUpOnlyPackage()
            R.id.btnPullUpByUri -> pullUpByUri()
            R.id.btnPullUpSpecifyConditions -> pullUpSpecifyConditions()
        }
    }


    /**
     * 根据包名、Activit来拉起App
     */
    private fun pullUpByPackage() {
        PullUpUtils.pullUpByPackage(
            this,
            "com.xuanyuan.pullupclient",
            "com.xuanyuan.pullupclient.Test1Activity"
        )
    }

    private fun pullUpOnlyPackage() {
        PullUpUtils.pullUpOnlyPackage(this, "com.xuanyuan.pullupclient")
    }

    private fun pullUpByUri() {
        PullUpUtils.pullUpByUri(this, "csd://com.xuanyuan.pullup/cyn?type=110")
    }

    private fun pullUpSpecifyConditions() {
        ApkUtils.pullApp(this, "com.xuanyuan.pullupclient")
    }
}